#include<iostream>
using namespace std;
#define N 128
#define M 10
int res[N][M],bit[M];

int ones_num(int arr[],int len){
    int cnt=0;
    for(int i=0;i<len;i++)
        cnt += arr[i];
    return cnt;
}

void cpy_arr(int m,int k){
    for(int j=0;j<m;j++){
        res[k][j] = bit[j];
    }
}

void permutation(int m,int n,int i){
    memset(res,0,sizeof(res));
    memset(bit,0,sizeof(bit));
    int k,j,num,h;
    for(k=1;k<i;){
        num = ones_num(bit,m);
        if(num<n){
                if(bit[m-1]==0){
                    bit[m-1] = 1;
                    cpy_arr(m,k);
                    k++;
                }else{
                    bit[m-1] = 0;
                    j = m-2;
                    while(j>=0&&bit[j]==1){
                        bit[j] = 0;
                        j--;
                    }
                    if(j>=0&&bit[j]==0)
                        bit[j] = 1;
                    cpy_arr(m,k);
                    k++;
                }
        }else if(num==n){
                j=m-1;
                while(j>=0 && bit[j]==0)
                    j--;
                h = j;
                while(h>=0&&bit[h]==1)
                    h--;
                if(h<0)
                    break;
                else if(bit[h]==0){
                    bit[j] = 0;
                    j--;
                    while(j>h){
                        bit[j] = 0;
                        j--;
                    }
                    bit[h] = 1;
                    cpy_arr(m,k);
                    k++;
                }
            }
    }
    cout << k << endl;
    for(j=0;j<m;j++)
        cout << bit[j]<< " ";
    cout <<endl;
}


int main(){
    permutation(4,2,12);
    return 0;
}


